package com.kk.xhr.model.assembler;

import com.kk.xhr.common.pojo.DegreeEnum;
import com.kk.xhr.common.pojo.EmployeeFromEnum;
import com.kk.xhr.common.pojo.EmployeeStatusEnum;
import com.kk.xhr.common.pojo.GenderEnum;
import com.kk.xhr.common.pojo.WedStatusEnum;
import com.kk.xhr.model.dto.EmployeeDTO;
import com.kk.xhr.model.entity.Employee;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
 * 员工数据转换工具类
 *
 * @author kkmystery
 * @version 1.0 2021/2/28 11:30
 * @since 1.0.0
 */
@Mapper(componentModel = "spring")
public interface EmployeeStructKit {

    EmployeeStructKit INSTANCE = Mappers.getMapper(EmployeeStructKit.class);

    /**
     * dto -> entity
     *
     * @param dto dto
     * @return entity
     */
    Employee toEntity(EmployeeDTO dto);

    /**
     * entity -> dto
     *
     * @param entity entity
     * @return dto
     */
    EmployeeDTO toDto(Employee entity);

    /**
     * EmployeeStatusEnum类型 byte -> enum
     *
     * @param status 员工状态
     * @return EmployeeStatusEnum
     */
    default EmployeeStatusEnum statusConvertor(Byte status) {
        if (null == status) {
            return null;
        }
        return EmployeeStatusEnum.from(status);
    }

    /**
     * EmployeeStatusEnum类型 enum -> byte
     *
     * @param status 员工状态
     * @return byte
     */
    default Byte statusConvertor(EmployeeStatusEnum status) {
        if (null == status) {
            return null;
        }
        return status.getValue();
    }

    /**
     * EmployeeFromEnum类型 byte -> enum
     *
     * @param from 员工招聘途径byte
     * @return EmployeeFromEnum
     */
    default EmployeeFromEnum fromConvertor(Byte from) {
        if (null == from) {
            return null;
        }
        return EmployeeFromEnum.from(from);
    }

    /**
     * EmployeeFromEnum类型 enum -> byte
     *
     * @param from 员工招聘途径枚举
     * @return byte
     */
    default Byte fromConvertor(EmployeeFromEnum from) {
        if (null == from) {
            return null;
        }
        return from.getValue();
    }

    /**
     * DegreeEnum类型 byte -> enum
     *
     * @param from 员工学历byte
     * @return DegreeEnum
     */
    default DegreeEnum degreeConvertor(Byte from) {
        if (null == from) {
            return null;
        }
        return DegreeEnum.from(from);
    }

    /**
     * DegreeEnum类型 enum -> byte
     *
     * @param from 员工学历枚举
     * @return byte
     */
    default Byte degreeConvertor(DegreeEnum from) {
        if (null == from) {
            return null;
        }
        return from.getValue();
    }

    /**
     * WedStatusEnum类型 byte -> enum
     *
     * @param from 婚姻状态byte
     * @return WedStatusEnum
     */
    default WedStatusEnum wedConvertor(Byte from) {
        if (null == from) {
            return null;
        }
        return WedStatusEnum.from(from);
    }

    /**
     * WedStatusEnum类型 enum -> byte
     *
     * @param from 婚姻状态枚举
     * @return byte
     */
    default Byte wedConvertor(WedStatusEnum from) {
        if (null == from) {
            return null;
        }
        return from.getValue();
    }

    /**
     * GenderEnum类型 byte -> enum
     *
     * @param from 性别byte
     * @return GenderEnum
     */
    default GenderEnum genderConvertor(Byte from) {
        if (null == from) {
            return null;
        }
        return GenderEnum.from(from);
    }

    /**
     * GenderEnum类型 enum -> byte
     *
     * @param from 性别枚举
     * @return byte
     */
    default Byte genderConvertor(GenderEnum from) {
        if (null == from) {
            return null;
        }
        return from.getValue();
    }
}
